class navbar {

	constructor() {
		this.version = '2.00.00'
	}
	init(This, opt = {}) {
		let sliderWidth = opt.width || 96
		This.setData({
			tabs: opt.tabs || ["菜单一", "菜单二"],
			activeIndex: opt.activeIndex || 0,
			sliderOffset: 0,
			sliderLeft: 0,
			position: opt.position || 'fixed',
			top: opt.top || 0,
			hue:opt.hue || '#e4e5e6'
		})
		wx.getSystemInfo({
			success: function (res) {
				let winWidth = res.windowWidth
				if (opt.tabs.length > 4) {
					winWidth = 100 * opt.tabs.length
				}
				//21
				This.setData({
					sliderLeft: ((winWidth / This.data.tabs.length - sliderWidth) / 2) || 0,
					sliderOffset: (winWidth / This.data.tabs.length * This.data.activeIndex) || 0
				})
				opt.success && opt.success()
			}
		})
	}

	setClick(This, e) {
		This.setData({
			sliderOffset: e.currentTarget.offsetLeft,
			activeIndex: e.currentTarget.id || 0
		})
	}

}

export default new navbar()